package com.isoftstone.disk.role.controller;

import com.isoftstone.disk.mybatis.entity.PtRoleEntity;
import com.isoftstone.disk.mybatis.flexigrid.PadingRstType;
import com.isoftstone.disk.mybatis.flexigrid.PagingBean;
import com.isoftstone.disk.mybatis.ztree.ZtreeEntity;
import com.isoftstone.disk.role.entity.SearchRoleEntity;
import com.isoftstone.disk.role.service.RoleService;
import com.isoftstone.disk.spring.controller.BaseController;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/role")
public class RoleController extends BaseController {
    private Logger logger = LogManager.getLogger(this.getClass().getName());
    @Resource
    private RoleService roleService;
    @Secured("ROLE_cldk_data_role")
    @RequestMapping("/rolePage")
    public String rolePage(){
        return "role/rolePage";
    }
    @RequestMapping("/queryRoleListPage")
    @ResponseBody
    public PadingRstType<PtRoleEntity> queryRoleListPage(SearchRoleEntity search, PagingBean paging){
        logger.info(search);
        logger.info(paging);
        PadingRstType<PtRoleEntity> rstType =  roleService.queryRoleListPage(search,paging);
        return rstType;
    }
    @RequestMapping("/queryMenuZtreeListByRoleId")
    @ResponseBody
    public List<ZtreeEntity> queryMenuZtreeListByRoleId(@RequestParam("roleUuid") String roleUuid){
        List<ZtreeEntity> list = roleService.queryMenuZtreeListByRoleId(roleUuid);
        return list;
    }
    @RequestMapping("/saveSelectMenuInfo")
    @ResponseBody
    public String saveSelectMenuInfo(@RequestParam("roleId") String roleId,@RequestParam("menuIds")String menuIds){
        logger.info("roleId:" + roleId  +" menuIds：" + menuIds);
        roleService.saveSelectMenuInfo(roleId,menuIds);
        return jsonSuccess("role.menu.allocate.success");
    }
}
